<template>
    <div>
        <h3>录入房号信息</h3>
        <table class="table">
         <thead>
            <tr>
                <th>房号</th>
                <th><input type="text" v-model="obj.houseNumName"></th>
            </tr>
             <tr>
                <th>房型</th>
                <th>
                    <select v-model="obj.typdId">
                        <option value="0">请选择房型</option>
                        <option v-for="a in typedata" :value="a.roomTypeId">{{ a.roomTypeName }}</option>
                    </select>
                </th>
            </tr>
            <tr>
                <th>门店</th>
                <th>
                    <select v-model="obj.storeSId">
                        <option value="0">请选择门店</option>
                        <option v-for="a in storedata" :value="a.storeId">{{a.storeName }}</option>
                    </select>
                </th>
            </tr>
            <tr>
                <th>状态</th>
                <th>
                    <input type="radio" v-model="obj.start" name="aa" value="1">上架
                    <input type="radio" v-model="obj.start" name="aa" value="2">下架
                </th>
            </tr>
            <tr>
                <th colspan="2">
                 <input type="button" value="录入" class="btn btn-success" @click="addhouse">
                </th>
            </tr>
         </thead>
        </table>
        <a href="/showall">返回首页</a>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,onMounted } from 'vue';
import { useRouter } from 'vue-router';
const router=useRouter()
onMounted(()=>{
    bindtype()
    bindstore()
})
const obj=ref({
  "houseNumName": "",
  "typdId": 0,
  "storeSId": 0,
  "start": 1
})
const addhouse=()=>{
    axios.post('/api/HouseNum/AddHouse',obj.value).then(res=>{
    if(res.data==-1)
     {
        alert('相同的房号只能出现一次!!')
        return;
     }
     else if(res.data>0)
     {
        alert('录入成功!!')
        router.push('/showhouse')
     }
    else
    {
        alert('录入失败!!')
        return;
    }
    })
}

//绑定房型下拉框
const  typedata=ref([{
     "roomTypeId": 1,
    "roomTypeName": "单人房"
}])
const bindtype=()=>{
    axios.get('/api/RoomType/GetRoomType',{}).then(res=>{
        typedata.value=res.data
    })
}
const  storedata=ref([{
     "storeId": 1,
    "storeName": "安平大酒店",
}])
const bindstore=()=>{
    axios.get('/api/Store/GetAllStores',{}).then(res=>{
        storedata.value=res.data
    })
}
</script>

<style scoped>

</style>